<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="ls" uri="/ls-trade-tags"%>
<%@ include file="/common/taglibs.jsp"%>


<html>
<head>
<title>编辑单据</title>

<script type="text/javascript">
		$(document).ready(function() {
			$("#mainForm").validate();
		});
	
		function clickBtn(action,id,e){
			
			switch(action){
			case "close":
				window.location="order.action";
				return;
				
			case "useTemplate":
				if(""==$("#orderTemplateId").val()){
					return;
				}
				window.location="order!useTemplate.action?order.id="+$("#orderId").val()+"&order.orderTemplate.id="+$("#orderTemplateId").val();
				return;
				
			case "save":
				$("#mainForm").attr("action","order!save.action");
				break;	
				
			case "printReport":
				$("#mainForm").attr("action","order!printReport.action");
				$("#mainForm").attr("target","_blank");
				break;					
			}
			
			$("#mainForm").submit();
			$("#mainForm").attr("target","_self");
		}	

		function ajaxGetTotalPrice(){
			$.ajax({
				url : "order!ajaxGetTotalPrice.action?order.id=<s:property value='order.id'/>",
				cache : false,
				dataType : "text",
				async : true,
				success : function(data) {
					$("#totalPrice").attr("value",data);
				},
				error : function(data) {
					$("#errorMsgSpan").html(data);
				}
			});				
		}

	</script>
</head>
<body>
<s:if test="%{order!=null&&order.id!=null}">
	<div class="pageTitle">编辑单据</div>
</s:if>
<s:else>
	<div class="pageTitle">添加单据</div>
</s:else>


<s:form id="mainForm" name="mainForm" action="order!save.action"
	method="post">
	<s:hidden name="order.id" id="orderId"></s:hidden>
	<div class="form2">

		<span class="errorLabel" id="errorMsgSpan"></span>
		<s:actionerror/>
		<s:fielderror/>
		<s:actionmessage/>    

   <table cellspacing="0" cellpadding="0" border="0" width="100%">
	   <tr>
	   		<td width="45%">
				<table cellspacing="0" cellpadding="0" border="0">
					<tbody>
						<tr>
							<td class="sep"><img style="width: 180px;"
								src="../images/spacer.gif"></td>
							<td class="sep"><img style="width: 180px;"
								src="../images/spacer.gif"></td>
							<td class="sep sep2"><img src="../images/spacer.gif"></td>
						</tr>
						<tr>
							<td><label class="fLabel">单据名称</label>
							<div class="fField"><s:textfield cssClass="inputText required"
								cssStyle="width:130px" name="order.name" /></div>
							</td>
							<td><label class="fLabel">客戶名称</label>
							<div class="fField"><s:textfield cssClass="inputText required"
								cssStyle="width:130px" name="order.customerName" /></div>
							</td>
							<td><label class="fLabel">总计金额</label>
							<div class="fField">
							    <input type="text" id="totalPrice" value="<s:property value='@com.lightsaber.trade.core.common.util.Calc@leaveTwoDigital(order.totalPrice)'/>" style="width:130px" disabled="disabled"/> 元
							</div>
							</td>				
						</tr>
						<tr>
							<td colspan="3"><label class="fLabel">描述</label>
							<div class="fField"><s:textarea
								name="order.description" id="level1PlanningRemarks"
								cssClass="inputTextarea" cssStyle="width:500px; height:50px"></s:textarea>
							</div>
							</td>
						</tr>
					</tbody>
				</table>				   		
	   		</td>
	   		<td width="15%">&nbsp;</td>
	   		<td width="40%" align="right" valign="top">
					<table cellspacing="0" cellpadding="0" border="0">
						<tbody>
							<tr>
								<td width="100%">&nbsp;</td>
								<td>
									<label class="fLabel">单据模板</label>
									<div class="fField">
										 <s:select cssClass="inputSelect" cssStyle="width:155px" 
										           name="order.orderTemplate.id" id="orderTemplateId"
							            		   list="orderTemplateList" listKey="id" listValue="name"
							            		   headerKey="" headerValue="-- Select --">
										</s:select>
									</div>
								</td>
								<td valign="bottom">
									<div class="btnSet btnSetTypeA">
										<div class="left">
											<div class="button">
												<div class="left">
													<div class="right"><input type="button"
														onclick="clickBtn('useTemplate')" value="使用此模板" class="inputButton">
													</div>
												</div>
											</div>
										</div>
									</div>
								</td>								
							</tr>	
						</tbody>
					</table>							   		
	   		</td>
	   </tr>
   </table>


	<div class="btnSet btnSetTypeA">
		<div class="left">
			<div class="button">
				<div class="left">
					<div class="right"><input type="button"
						onclick="clickBtn('save')" value="保存" class="inputButton">
					</div>
				</div>
			</div>
	
			<div class="button">
				<div class="left">
					<div class="right">
						<input type="reset" value="重置" class="inputButton">
					</div>
				</div>
			</div>
	
			 <div class="button">
				<div class="left">
					<div class="right">
						<input type="button" onclick="clickBtn('close')" value="返回" class="inputButton">
					</div>
				</div>
			</div>
			
			 <div class="button">
				<div class="left">
					<div class="right">
						<input type="button" onclick="clickBtn('printReport')" value="打印" class="inputButton">
					</div>
				</div>
			</div>			
		</div>
	</div>

	</div>
</s:form>

<s:if test="%{order!=null&&order.id!=null}">
	<div class="pageTitle2">单据项</div>
	<iframe id="orderItemIframe" name="orderItemIframe"
		src="order-item.action?no-decorate&orderId=<s:property value='order.id'/>"
		style="width: 100%; height: 150px;" frameborder="0" scrolling="no">
	</iframe>
</s:if>

</body>
</html>